package org.jeecg.modules.demo.domain.types;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.query.QueryRuleEnum;
import org.jeecg.modules.demo.domain.types.entity.CmsDomainType;
import org.jeecg.modules.demo.domain.types.service.ICmsDomainTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Tag(name="专家信息表")
@RestController
@RequestMapping("/api/cms_domain")
@Slf4j
public class WebCmsDomainTypesController {
    @Autowired
    private ICmsDomainTypeService cmsDomainTypeService;
    @Operation(summary="领域列表查询")
    @GetMapping(value = "/get_domain_list_by_root")
    public Result<List<Map>> get_domain_list_by_root(String parent_id,HttpServletRequest req) {
        String pid ;
        if(parent_id!=null && !parent_id.equals("")){
            pid = parent_id;
        }else{
            pid = "0";
        }

        CmsDomainType cmsDomainTypeParams = new CmsDomainType();
        cmsDomainTypeParams.setPid(pid);
        // 自定义查询规则
        Map<String, QueryRuleEnum> customeRuleMap = new HashMap<>();
        // 自定义多选的查询规则为：LIKE_WITH_OR
//        customeRuleMap.put("isVerified", QueryRuleEnum.LIKE_WITH_OR);
//        QueryGenerator.initQueryWrapper(cmsDomainTypeParams, req.getParameterMap(),customeRuleMap);
//        QueryWrapper<CmsDomainType> queryWrapper = QueryGenerator.initQueryWrapper(cmsDomainTypeParams, req.getParameterMap(),customeRuleMap);
        QueryWrapper<CmsDomainType> queryWrapper = QueryGenerator.initQueryWrapper(cmsDomainTypeParams, req.getParameterMap());
        List<CmsDomainType> cmsDomainTypeList = cmsDomainTypeService.list(queryWrapper);
        List<Map> list = new ArrayList<>();
        for(CmsDomainType cmsDomainType1:cmsDomainTypeList){
            Map<String,String> map = new HashMap<>();
            map.put("id",cmsDomainType1.getId());
            map.put("title",cmsDomainType1.getTypeName());
            map.put("type_code",cmsDomainType1.getTypeCode());
            list.add(map);
        }
        return Result.OK(list);
    }
}
